package com.weike.yuanding.strategy.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weike.yuanding.constant.UserVideoRelationEnum;
import com.weike.yuanding.core.domain.R;
import com.weike.yuanding.dto.user.UserFriendDTO;
import com.weike.yuanding.entity.VideoMainEntity;
import com.weike.yuanding.feign.user.UserService;
import com.weike.yuanding.mapper.VideoMainMapper;
import com.weike.yuanding.service.VideoService;
import com.weike.yuanding.strategy.VideoStrategy;
import com.weike.yuanding.utils.BaseContext;
import com.weike.yuanding.vo.VideoResVo;
import com.weike.yuanding.vo.VideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 观看历史视频策略
 */
@Component("8")
public class HistoryVideoStrategy implements VideoStrategy {

    @Autowired
    private VideoMainMapper videoMainMapper;

    @Autowired
    private VideoService videoService;

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private UserService userService;

    /**
     * 推荐算法
     * @param videoVo 输入参数
     * @return 推荐的视频列表
     */
    @Override
    public List<VideoResVo> getVideoList(VideoVo videoVo) {
        // 获取当前用户ID


        Set<String> idSet = redisTemplate.opsForSet().members("user:video:viewed:" + videoVo.getUserId());

        if (idSet == null || idSet.isEmpty()) {
            return new ArrayList<>();
        }
        List<String> idList = new ArrayList<>(idSet);
        return videoService.list(idList);
    }

}
